#include "qdisplayresult.h"

QDisplayResult::QDisplayResult(QVBoxLayout* layout,QObject* parent )
   :QObject(parent), m_layout(layout)
{
}

QDisplayResult::~QDisplayResult()
{

}


void QDisplayResult::setResultsToDisplay(const QList<QBDDItem*>& results)
{
	clearLayout();
	foreach(QBDDItem* item, results)
	{
		QSearchResult* result = new QSearchResult(item);
		connect(result,SIGNAL(partSelected(const QStringList&)),this,SLOT(acceptedResult(const QStringList&)));
		m_layout->addWidget(result);
	}
}

void QDisplayResult::clearLayout()
{
	while(m_layout->count())
	{
		QWidget* widget = m_layout->itemAt(0)->widget();
		widget->disconnect();
		m_layout->removeWidget(widget);
		delete (QSearchResult*) widget;
	}
}

void QDisplayResult::acceptedResult(const QStringList& part)
{
	emit partModified(part);
}